﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using App.Interface;
using App.Info;
using App.Utility;

namespace App.Implement
{
    public class UserFbImpl : IUserFb
    {
        public bool Update(UserFbInfo info)
        {
            SqlParameter[] sqlParameters = {
                                                   new SqlParameter("@AppID", info.AppID),
                                                   new SqlParameter("@UserId", info.UserId),
                                                   new SqlParameter("@birthday",info.birthday),
                                                   new SqlParameter("@Username", info.Username),
                                                   new SqlParameter("@sToken", info.sToken),
                                                   new SqlParameter("@sContent", info.sContent),
                                                   new SqlParameter("@active", info.Active)
                                               };
            return (DataHelper.ExecuteNonQuery(Config.ConnectionString, "UserFb_Update", sqlParameters) > 0);
        }

        public bool UpdateSttSend(int id, bool isSendOk)
        {
            SqlParameter[] sqlParameters = {
                                                   new SqlParameter("@id", id),
                                                   new SqlParameter("@isSend", isSendOk)
                                               };
            return (DataHelper.ExecuteNonQuery(Config.ConnectionString, "UserFb_Update_Stt_Send_id", sqlParameters) > 0);
        }

        public bool UpdateSttSend(string AppId, string UserId, bool isSendOk)
        {
            SqlParameter[] sqlParameters = {
                                                   new SqlParameter("@AppID", AppId),
                                                   new SqlParameter("@UserId", UserId),
                                                   new SqlParameter("@isSend",isSendOk)
                                               };
            return (DataHelper.ExecuteNonQuery(Config.ConnectionString, "UserFb_Update_Stt_Send_UserId_AppId", sqlParameters) > 0);
        }


        public List<UserFbInfo> SelectAll(string AppId)
        {
            List<UserFbInfo> list = null;
            var param = new[]
                            {
                                new SqlParameter("@AppID", SqlDbType.Int) {Value = AppId}
                            };
            //SqlCommand com;
            //var r = DataHelper.ExecuteReader(Config.ConnectionString, "UserFb_Select_List_All", param, out com);
            var r = DataHelper.ExecuteReader(Config.ConnectionString, "UserFb_Select_List_All", param);
            list = new List<UserFbInfo>();
            while (r.Read())
            {
                list.Add(new UserFbInfo
                {
                    id = Convert.ToInt32(r["id"].ToString()),
                    AppID = r["AppID"].ToString(),
                    UserId = r["UserId"].ToString(),
                    birthday = Convert.ToDateTime(r["birthday"]),
                    Username = r["Username"].ToString(),
                    sToken = r["sToken"].ToString(),
                    sContent = r["sContent"].ToString(),
                    iSendOk = Convert.ToInt32(r["iSendOk"]),
                    iSendFalse = Convert.ToInt32(r["iSendFalse"]),
                    Active = Convert.ToBoolean(r["Active"]),
                    CreateDate = Convert.ToDateTime(r["CreateDate"].ToString())
                });
            }
            r.Close();
            r.Dispose();
            return list;
        }

        public List<UserFbInfo> SelectList(string AppId)
        {
            throw new NotImplementedException();
        }

        public List<UserFbInfo> GetList(string AppId, int pageIndex, int pageSize, out int totalRow)
        {
            throw new NotImplementedException();
        }
    }
}
